//
//  MXHomeWebViewVC.m
//  MXの衣柜
//
//  Created by 马霄 on 15/8/10.
//  Copyright (c) 2015年 霄 马. All rights reserved.
// 首页商品田苗跳转webView
#define WIDTH ([UIScreen mainScreen].bounds.size.width)
#define HEIGHT ([UIScreen mainScreen].bounds.size.height)
#import "MXHomeWebViewVC.h"
#import "MBProgressHUD.h"
@interface MXHomeWebViewVC ()<UIWebViewDelegate>
@property (nonatomic, retain) MBProgressHUD *HUD;
@property (nonatomic, retain) UIWebView *webView;
@property (nonatomic, retain) UIView *alterView;
@end

@implementation MXHomeWebViewVC
- (void)dealloc
{
    [_alterView release];
    [_HUD release];
    _webView.delegate = nil;
    [_titleSring release];
    [_requestString release];
    [_webView release];
    [super dealloc];
}

-(void)viewWillAppear:(BOOL)animated
{
    [self uiActivityindicatorviewStart];
    
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(uiActivityindicatorviewEnd) userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];

}
-(void)viewDidAppear:(BOOL)animated
{
    [self uiActivityindicatorviewEnd];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    self.title = @"宝贝详情";
    self.navigationController.navigationBar.hidden = NO;
    self.webView = [[[UIWebView alloc] initWithFrame:CGRectMake(0, WIDTHPRO * 64, WIDTH, HEIGHT - HEIGHTPRO * 64)] autorelease];
    
    self.webView.delegate = self;
    
    self.webView.userInteractionEnabled = YES;
    
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.requestString]];
        
    [self.view addSubview:self.webView];
    
    [self.webView loadRequest:request];
    
    // Do any additional setup after loading the view.
    {
    UILabel *titleLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHTPRO * 64)] autorelease];
    titleLabel.backgroundColor = [UIColor whiteColor];
    titleLabel.userInteractionEnabled = YES;
    titleLabel.text = @"";
    [self.view addSubview:titleLabel];
    
    UILabel *ItemTitleLabel = [[[UILabel alloc] initWithFrame:CGRectMake(WIDTH / 2 - 40, HEIGHTPRO * 24,WIDTHPRO * 80, HEIGHTPRO * 40)] autorelease];
    ItemTitleLabel.text = @"宝贝详情";
    
    if (self.titleSring) {
        ItemTitleLabel.text = self.titleSring;
    }

    [ItemTitleLabel setTextColor:[UIColor redColor]];
    [titleLabel addSubview:ItemTitleLabel];
    
    UIButton *backButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    backButton.frame = CGRectMake(WIDTHPRO * 10, HEIGHTPRO * 29, WIDTHPRO * 20, HEIGHTPRO * 20);
    backButton.backgroundColor = [UIColor clearColor];
    [backButton setBackgroundImage:[UIImage imageNamed:@"Tmall_back"] forState:(UIControlStateNormal)];
    [backButton addTarget:self action:@selector(backAction) forControlEvents:(UIControlEventTouchUpInside)];
    [titleLabel addSubview:backButton];
    }
    
}


-(void)uiActivityindicatorviewStart
{
    self.alterView =[[[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)] autorelease];
    self.alterView.backgroundColor =[UIColor whiteColor];
    self.HUD = [MBProgressHUD showHUDAddedTo:self.alterView animated:YES];
//    self.HUD.labelText = @"正在努力的给您加载";
    [self.HUD show:YES];
    
    [self.view addSubview:self.alterView];
    
}
-(void)uiActivityindicatorviewEnd
{
    [self.alterView removeFromSuperview];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)backAction
{
    [self dismissViewControllerAnimated:YES completion:^{
    }];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
